/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clientereligadora.formularios;

import static clientereligadora.paineis.PainelChart.jPanel2;
import java.awt.BorderLayout;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.jdbc.JDBCPieDataset;
import org.jfree.util.Rotation;

/**
 *
 * @author leandro.aquino
 */
public final class FormGrafico extends javax.swing.JFrame {
  
    /**
     * Creates new form FormGrafico
     */
    public FormGrafico() throws SQLException   {
          
        initComponents();
      chamaPie();
        
        
    }
   
public void chamaPie() throws SQLException{
     try {       
            pieChart();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(FormGrafico.class.getName()).log(Level.SEVERE, null, ex);
        } 
}
 
    public void pieChart() throws SQLException, ClassNotFoundException {
        String query = "select evento.id_religadora AS RELIGADORA, evento.tipo_evento AS EVENTO from dataserverreligadora.evento "
                + "WHERE `data` > 2013-01-04 "
                + "ORDER BY id_religadora";

        JDBCPieDataset dataset1 = new JDBCPieDataset("jdbc:mysql://localhost:3306/dataserverreligadora", "com.mysql.jdbc.Driver",
                "root", "ntk1120");

        dataset1.executeQuery(query);
        System.out.println(query);
        System.out.println(dataset1);

        JFreeChart chart = ChartFactory.createPieChart(" Religadora", dataset1, true, true, true);

        // JFreeChart chart = ChartFactory.createPieChart(query, dataset1, rootPaneCheckingEnabled, rootPaneCheckingEnabled, Locale.)
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(650, 270));

        JFreeChart chart1 = ChartFactory.createPieChart3D(" Religadora", dataset1, true, true, true);

        final PiePlot3D plot = (PiePlot3D) chart1.getPlot();
        plot.setStartAngle(290);
        plot.setDirection(Rotation.CLOCKWISE);
        plot.setForegroundAlpha(0.5f);
        plot.setNoDataMessage("No data to display");
        plot.setIgnoreZeroValues(true);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2} "));

       ChartPanel chartPanel1 = new ChartPanel(chart1);
        chartPanel1.setDomainZoomable(true);
      // pchart.jScrollPane1.add(new ChartPanel(chart1));
     jPanel1.add(chartPanel1,BorderLayout.CENTER);
     jPanel1.validate();

    //    jScrollPane1.setViewportView(chartPanel1);

     //  jScrollPane1.setViewportView(chartPanel1);
 

//PiePlot plotagem = (PiePlot) chart.getPlot();  
//define porcentagem no gráfico  

    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel1.setPreferredSize(new java.awt.Dimension(720, 459));
        jPanel1.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormGrafico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormGrafico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormGrafico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormGrafico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new FormGrafico().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(FormGrafico.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
